<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>

                    <p:panel header="Category Stock Summery" >

                        <h:panelGrid columns="2" >
                            <h:outputLabel value="Department" ></h:outputLabel>
                            <p:autoComplete completeMethod="#{departmentController.completeDept}" 
                                            var="dept" itemLabel="#{dept.name}" itemValue="#{dept}" 
                                            forceSelection="true" value="#{reportsStock.department}" converter="departmentConverter"/>
                        </h:panelGrid>
                         <h:panelGrid columns="3" >
                              <p:commandButton ajax="false" value="Process" 
                                              actionListener="#{reportsStock.fillCategoryStocksByCatagory()}" ></p:commandButton>
                            <p:commandButton value="Print" ajax="false" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                <pe:exporter type="xlsx" target="tbl" fileName="Category_report"  />
                            </p:commandButton>  
                        </h:panelGrid>

                        <h:panelGroup id="gpBillPreview" styleClass="noBorder summeryBorder">
                            <p:dataTable id="tbl"  value="#{reportsStock.stockRecords}" var="i" style="width: 500px;" >
                                <f:facet name="header">
                                    <h:outputLabel value="Category Stock Summery - #{reportsStock.department.name} "/>   <br/>                                 
                                </f:facet> 

                                <p:column headerText="Category"
                                          sortBy="#{i.category.name}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Category" style="float: left"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.category.name}"></h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="Total" style="float: left"/>    
                                    </f:facet>
                                </p:column>

                                <p:column headerText="Stock Value" 
                                          style="text-align: right;" 
                                          styleClass="averageNumericColumn"
                                          sortBy="#{i.stockOnHand}">
                                    <f:facet name="header">
                                        <h:outputLabel value="Stock Value" style="float: right;"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.stockOnHand}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>      
                                    <f:facet name="footer" >
                                        <h:outputLabel value="#{reportsStock.totalPurchaseValue}" style="float: right;">
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>
                        </h:panelGroup>
                        <p:panel>
                            <h:outputLabel value="Printed At " ></h:outputLabel>
                            <h:outputLabel value="#{sessionController.currentDate}" >
                                <f:convertDateTime pattern="dd MMMM yyyy - hh:mm a" ></f:convertDateTime>
                            </h:outputLabel>
                        </p:panel>
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>

    </h:body>
</html>
